/*
	The Sentinel by Copy112 & Bekka
*/

//Dimension variables
local w = ScrW()
local h = ScrH()

function GM:StartScreen()
	if game.GetMap() == self.StartingMap then
		Title = vgui.Create("DLabel")
		Title:SetSize( w * 0.65, h * 0.3 )
		Title:SetPos( w * 0.15, h * 0.025 )
		Title:SetText( "" )
		function Title:Paint()
			surface.CreateFont ("HUDNumber5", ScreenScale(60), 600, false, false, "HUDNumber9")
			draw.SimpleTextOutlined("Sentinel", "HUDNumber9", Title:GetWide() * 0.5, Title:GetTall() * 0.2, Color(41, 156, 173, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, Color(247, 247, 33, 255))
			draw.SimpleText("Remake written by", "Trebuchet24", Title:GetWide() * 0.5, Title:GetTall() * 0.5, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
			draw.SimpleText("Bekka and Copy112", "Trebuchet24", Title:GetWide() * 0.5, Title:GetTall() * 0.8, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
		end
	
		StartButton = vgui.Create( "DButton" )
		StartButton:SetSize( w * 0.25, h * 0.1 )
		StartButton:SetPos( w * 0.35, h * 0.5 )
		StartButton:SetText( "" )
		StartButton.Color = Color(192, 192, 192, 255)
		function StartButton:Paint()	
			surface.SetDrawColor( 255, 198, 0, 255 )
			surface.DrawOutlinedRect( 0, 0, StartButton:GetWide(), StartButton:GetTall() )
			for i = 1, 10 do
				surface.DrawOutlinedRect( i / 2, i / 2, StartButton:GetWide() - i , StartButton:GetTall() - i )
			end
			surface.SetDrawColor( 44, 105, 154, 100 )
			surface.DrawRect( 5, 5, StartButton:GetWide() - 10, StartButton:GetTall() - 10 )
			draw.SimpleTextOutlined("Start", "HUDNumber5", StartButton:GetWide() * 0.5, StartButton:GetTall() * 0.5, self.Color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, Color(0,0,0,255))
		end
		function StartButton:DoClick()
			surface.PlaySound("mouse/msfxMouseClick.wav" )
			ConfigButton:Remove()
			StartButton:Remove()
			QuitButton:Remove()
			Title:Remove()
			GAMEMODE:PlayerSelection()
		end
		function StartButton:OnCursorEntered()
			surface.PlaySound( "mouse/msfxMouseOver.wav" )
			StartButton.Color = Color(255,255,255,255)
		end
		function StartButton:OnCursorExited()
			StartButton.Color = Color(192,192,192,255)
		end
	
	
		ConfigButton = vgui.Create( "DButton" )
		ConfigButton:SetSize( w * 0.25, h * 0.1 )
		ConfigButton:SetPos( w * 0.35, h * 0.65 )
		ConfigButton:SetText( "" )
		ConfigButton.Color = Color(192,192,192,255)
		function ConfigButton:Paint()	
			surface.SetDrawColor( 255, 198, 0, 255 )
			surface.DrawOutlinedRect( 0, 0, ConfigButton:GetWide(), ConfigButton:GetTall() )
			for i = 1, 10 do
				surface.DrawOutlinedRect( i / 2, i / 2, ConfigButton:GetWide() - i , ConfigButton:GetTall() - i )
			end
			surface.SetDrawColor( 44, 105, 154, 100 )
			surface.DrawRect( 5, 5, ConfigButton:GetWide() - 10, ConfigButton:GetTall() - 10 )
			draw.SimpleTextOutlined("Config", "HUDNumber5", ConfigButton:GetWide() * 0.5, ConfigButton:GetTall() * 0.5, self.Color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, Color(0,0,0,255))
		end
		function ConfigButton:DoClick()
			surface.PlaySound("mouse/msfxMouseClick.wav" )
		end
		function ConfigButton:OnCursorEntered()
			surface.PlaySound("mouse/msfxMouseOver.wav" )
			ConfigButton.Color = Color(255,255,255,255)
		end
		function ConfigButton:OnCursorExited()
			ConfigButton.Color = Color(192,192,192,255)
		end
	
		QuitButton = vgui.Create( "DButton" )
		QuitButton:SetSize( w * 0.25, h * 0.1 )
		QuitButton:SetPos( w * 0.35, h * 0.8 )
		QuitButton:SetText( "" )
		QuitButton.Color = Color(192,192,192,255)
		function QuitButton:Paint()	
			surface.SetDrawColor( 255, 198, 0, 255 )
			surface.DrawOutlinedRect( 0, 0, QuitButton:GetWide(), QuitButton:GetTall() )
			for i = 1, 10 do
				surface.DrawOutlinedRect( i / 2, i / 2, QuitButton:GetWide() - i , QuitButton:GetTall() - i )
			end
			surface.SetDrawColor( 44, 105, 154, 100 )
			surface.DrawRect( 5, 5, QuitButton:GetWide() - 10, QuitButton:GetTall() - 10 )
			draw.SimpleTextOutlined("Quit", "HUDNumber5", QuitButton:GetWide() * 0.5, QuitButton:GetTall() * 0.5, self.Color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, Color(0,0,0,255))
		end
		function QuitButton:DoClick()
		surface.PlaySound("mouse/msfxMouseClick.wav" )
			RunConsoleCommand("disconnect")
		end
		function QuitButton:OnCursorEntered()
			surface.PlaySound("mouse/msfxMouseOver.wav" )
			self.Color = Color(255,255,255,255)
		end
		function QuitButton:OnCursorExited()
			self.Color = Color(192,192,192,255)
		end
	end
end

hook.Add( "Initialize", "MakeStartMenu", function() if game.GetMap() != GAMEMODE.StartingMap then gui.EnableScreenClicker( false ) else GAMEMODE:StartScreen()  gui.EnableScreenClicker( true )  end end )

function CalcView( ply, origin, angles, fov ) 
	if game.GetMap() == GAMEMODE.StartingMap then
		local view = {} 
		view.origin = Vector(math.cos( math.rad( CurTime()* 5)) * 360,math.sin( math.rad( CurTime() * 5 ))* 360,0)
		local ent = ents.FindByClass("camera_view")[1]
		if ent && ent:IsValid() then
			local targetpos = ent:LocalToWorld( ent:OBBCenter() )
			local aimvector = targetpos - Vector(math.cos( math.rad( CurTime()* 5)) * 360,math.sin( math.rad( CurTime() * 5 ))* 360,0)
			view.angles = aimvector:Angle()
		end

		return view
	end
end

hook.Add( "CalcView" , "CalcView" , CalcView )

function GM:PlayerSelection()

	Title = vgui.Create("DLabel")
	Title:SetSize( w * 0.7, h * 0.3 )
	Title:SetPos( w * 0.15, h * 0.025 )
	Title:SetText( "" )
	function Title:Paint()
		surface.CreateFont ("HUDNumber5", ScreenScale(60), 600, false, false, "HUDNumber9")
		draw.SimpleTextOutlined("Choose a gametype", "HUDNumber9", Title:GetWide() * 0.5, Title:GetTall() * 0.2, Color(41, 156, 173, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, Color(247, 247, 33, 255))
	end
	
	SinglePlayerButton = vgui.Create( "DButton" )
	SinglePlayerButton:SetSize( w * 0.3, h * 0.1 )
	SinglePlayerButton:SetPos( w * 0.05, h * 0.5 )
	SinglePlayerButton:SetText( "" )
	SinglePlayerButton.Color = Color(192, 192, 192, 255)
	function SinglePlayerButton:Paint()	
		surface.SetDrawColor( 255, 198, 0, 255 )
		surface.DrawOutlinedRect( 0, 0, SinglePlayerButton:GetWide(), SinglePlayerButton:GetTall() )
		for i = 1, 10 do
			surface.DrawOutlinedRect( i / 2, i / 2, SinglePlayerButton:GetWide() - i , SinglePlayerButton:GetTall() - i )
		end
		surface.SetDrawColor( 44, 105, 154, 100 )
		surface.DrawRect( 5, 5, SinglePlayerButton:GetWide() - 10, SinglePlayerButton:GetTall() - 10 )
		draw.SimpleTextOutlined("SinglePlayer", "HUDNumber5", SinglePlayerButton:GetWide() * 0.5, SinglePlayerButton:GetTall() * 0.5, self.Color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, Color(0,0,0,255))
	end
	function SinglePlayerButton:DoClick()
		surface.PlaySound("mouse/msfxMouseClick.wav" )
		Title:Remove()
		SinglePlayerButton:Remove()
		MultiPlayer:Remove()
		GAMEMODE:SinglePlayer()
	end
	function SinglePlayerButton:OnCursorEntered()
		surface.PlaySound("mouse/msfxMouseOver.wav" )
		if SinglePlayer() then SinglePlayerButton.Color = Color(255,255,255,255) end
		if !SinglePlayer() then SinglePlayerButton.Color = Color(255,0,0,255) end
	end
	function SinglePlayerButton:OnCursorExited()
		SinglePlayerButton.Color = Color(192,192,192,255)
	end
	
	MultiPlayer = vgui.Create( "DButton" )
	MultiPlayer:SetSize( w * 0.3, h * 0.1 )
	MultiPlayer:SetPos( w * 0.65, h * 0.5 )
	MultiPlayer:SetText( "" )
	MultiPlayer.Color = Color(192, 192, 192, 255)
	function MultiPlayer:Paint()	
		surface.SetDrawColor( 255, 198, 0, 255 )
		surface.DrawOutlinedRect( 0, 0, MultiPlayer:GetWide(), MultiPlayer:GetTall() )
		for i = 1, 10 do
			surface.DrawOutlinedRect( i / 2, i / 2, MultiPlayer:GetWide() - i , MultiPlayer:GetTall() - i )
		end
		surface.SetDrawColor( 44, 105, 154, 100 )
		surface.DrawRect( 5, 5, MultiPlayer:GetWide() - 10, MultiPlayer:GetTall() - 10 )
		draw.SimpleTextOutlined("Multiplayer", "HUDNumber5", MultiPlayer:GetWide() * 0.5, MultiPlayer:GetTall() * 0.5, self.Color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, Color(0,0,0,255))
	end
	function MultiPlayer:DoClick()
		surface.PlaySound("mouse/msfxMouseClick.wav" )
	end
	function MultiPlayer:OnCursorEntered()
		surface.PlaySound("mouse/msfxMouseOver.wav" )
		if SinglePlayer() then MultiPlayer.Color = Color(255,0,0,255) end
		if !SinglePlayer() then MultiPlayer.Color = Color(255,255,255,255) end
	end
	function MultiPlayer:OnCursorExited()
		MultiPlayer.Color = Color(192,192,192,255)
	end

end

function GM:SinglePlayer()

		Stagelist = vgui.Create( "DPanelList" )
        Stagelist:SetPos( w * 0.1, h * 0.1 )
		Stagelist:SetSize( w * 0.8, h * 0.4 )
        Stagelist:EnableHorizontal( false )
		Stagelist:EnableVerticalScrollbar( true )
        Stagelist:SetPadding( 5 )
        Stagelist:SetSpacing( 5 )
		function Stagelist:Paint()	
			surface.SetDrawColor( 255, 198, 0, 255 )
			surface.DrawOutlinedRect( 0, 0, Stagelist:GetWide(), Stagelist:GetTall() )
				for i = 1, 10 do
					surface.DrawOutlinedRect( i / 2, i / 2, Stagelist:GetWide() - i , Stagelist:GetTall() - i )
				end
			surface.SetDrawColor( 44, 105, 154, 100 )
			surface.DrawRect( 5, 5, Stagelist:GetWide() - 10, Stagelist:GetTall() - 10 )
		end
		
		
	StageListView = vgui.Create("DListView")
	StageListView:SetParent(Stagelist)
	StageListView:SetPos(5, 5)
	StageListView:SetSize(Stagelist:GetWide() - 10, Stagelist:GetTall() - 10)
	StageListView:SetMultiSelect(false)
	function StageListView:Paint()
	end
	StageListView:AddColumn("Stage")
	StageListView:AddColumn("Code")
	
	for k, v in pairs( GAMEMODE.MapList ) do
		StageListView:AddLine( k, v )
	end


	SinglePlayerOKButton = vgui.Create( "DButton" )
	SinglePlayerOKButton:SetSize( w * 0.3, h * 0.1 )
	SinglePlayerOKButton:SetPos( w * 0.15, h * 0.85 )
	SinglePlayerOKButton:SetText( "" )
	SinglePlayerOKButton.Color = Color(192, 192, 192, 255)
	function SinglePlayerOKButton:Paint()	
		surface.SetDrawColor( 255, 198, 0, 255 )
		surface.DrawOutlinedRect( 0, 0, SinglePlayerOKButton:GetWide(), SinglePlayerOKButton:GetTall() )
		for i = 1, 10 do
			surface.DrawOutlinedRect( i / 2, i / 2, SinglePlayerOKButton:GetWide() - i , SinglePlayerOKButton:GetTall() - i )
		end
		surface.SetDrawColor( 44, 105, 154, 100 )
		surface.DrawRect( 5, 5, SinglePlayerOKButton:GetWide() - 10, SinglePlayerOKButton:GetTall() - 10 )
		draw.SimpleTextOutlined("OK", "HUDNumber5", SinglePlayerOKButton:GetWide() * 0.5, SinglePlayerOKButton:GetTall() * 0.5, self.Color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, Color(0,0,0,255))
	end
	function SinglePlayerOKButton:DoClick()
		surface.PlaySound("mouse/msfxMouseClick.wav" )
		if StageListView:GetLine(StageListView:GetSelectedLine()) then
			for k, v in pairs( GAMEMODE.MapList ) do
				if k == StageListView:GetLine(StageListView:GetSelectedLine()):GetValue(1) then
					RunConsoleCommand("changelevel", v )
				end
			end
		end
	end
	function SinglePlayerOKButton:OnCursorEntered()
		surface.PlaySound("mouse/msfxMouseOver.wav" )
		SinglePlayerOKButton.Color = Color(255,255,255,255)
	end
	function SinglePlayerOKButton:OnCursorExited()
		SinglePlayerOKButton.Color = Color(192,192,192,255)
	end
	
	MainMenu = vgui.Create( "DButton" )
	MainMenu:SetSize( w * 0.3, h * 0.1 )
	MainMenu:SetPos( w * 0.5, h * 0.85 )
	MainMenu:SetText( "" )
	MainMenu.Color = Color(192, 192, 192, 255)
	function MainMenu:Paint()	
		surface.SetDrawColor( 255, 198, 0, 255 )
		surface.DrawOutlinedRect( 0, 0, MainMenu:GetWide(), MainMenu:GetTall() )
		for i = 1, 10 do
			surface.DrawOutlinedRect( i / 2, i / 2, MainMenu:GetWide() - i , MainMenu:GetTall() - i )
		end
		surface.SetDrawColor( 44, 105, 154, 100 )
		surface.DrawRect( 5, 5, MainMenu:GetWide() - 10, MainMenu:GetTall() - 10 )
		draw.SimpleTextOutlined("MAIN MENU", "HUDNumber5", MainMenu:GetWide() * 0.5, MainMenu:GetTall() * 0.5, self.Color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, Color(0,0,0,255))
	end
	function MainMenu:DoClick()
		surface.PlaySound("mouse/msfxMouseClick.wav" )
		Stagelist:Remove()
		StageListView:Remove()
		SinglePlayerOKButton:Remove()
		LevelNumber:Remove()
		LevelCode:Remove()
		LevelNumberTxt:Remove()
		LevelCodeTxt:Remove()
		MainMenu:Remove()
		GAMEMODE:StartScreen()
	end
	function MainMenu:OnCursorEntered()
		surface.PlaySound("mouse/msfxMouseOver.wav" )
		MainMenu.Color = Color(255,255,255,255)
	end
	function MainMenu:OnCursorExited()
		MainMenu.Color = Color(192,192,192,255)
	end
	
	LevelNumber	= vgui.Create("DLabel")
	LevelNumber:SetSize( w * 0.35, h * 0.1 )
	LevelNumber:SetPos( w * 0.1, h * 0.55 )
	LevelNumber:SetText("")
	function LevelNumber:Paint()	
		surface.SetDrawColor( 44, 105, 154, 100 )
		surface.DrawRect( 5, 5, LevelNumber:GetWide(), LevelNumber:GetTall() )
		draw.SimpleTextOutlined("Level Number:", "HUDNumber5", LevelNumber:GetWide() * 0.5, LevelNumber:GetTall() * 0.5, Color(192, 192, 192, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, Color(0,0,0,255))
	end
	
	LevelNumberTxt = vgui.Create("DTextEntry")
	LevelNumberTxt:SetSize( w * 0.35, h * 0.1 )
	LevelNumberTxt:SetPos( w * 0.5, h * 0.55 )
	LevelNumberTxt:SetText("Hai")
	function LevelNumberTxt:Paint()
		surface.SetDrawColor( 255, 198, 0, 255 )
		surface.DrawOutlinedRect( 0, 0, LevelNumberTxt:GetWide(), LevelNumberTxt:GetTall() )
		for i = 1, 10 do
			surface.DrawOutlinedRect( i / 2, i / 2, LevelNumberTxt:GetWide() - i , LevelNumberTxt:GetTall() - i )
		end
		surface.SetDrawColor( 255, 255, 255, 255 )
		surface.DrawRect( 5, 5, LevelNumberTxt:GetWide() - 10, LevelNumberTxt:GetTall() - 10 )
		if StageListView:GetLine(StageListView:GetSelectedLine()) then
			draw.SimpleTextOutlined(tostring(StageListView:GetLine(StageListView:GetSelectedLine()):GetValue(1)), "HUDNumber5", 10, LevelNumberTxt:GetTall() * 0.2, Color( 255, 255, 255, 255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT, 2, Color(0,0,0,255))
		end
	end

	LevelCode = vgui.Create("DLabel")
	LevelCode:SetSize( w * 0.35, h * 0.1 )
	LevelCode:SetPos( w * 0.1, h * 0.7 )
	LevelCode:SetText("")
	function LevelCode:Paint()	
		surface.SetDrawColor( 44, 105, 154, 100 )
		surface.DrawRect( 5, 5, LevelCode:GetWide(), LevelCode:GetTall() )
		draw.SimpleTextOutlined("Level Name:", "HUDNumber5", LevelCode:GetWide() * 0.5, LevelCode:GetTall() * 0.5, Color(192, 192, 192, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, Color(0,0,0,255))
	end
	
	LevelCodeTxt = vgui.Create("DTextEntry")
	LevelCodeTxt:SetSize( w * 0.35, h * 0.1 )
	LevelCodeTxt:SetPos( w * 0.5, h * 0.7 )
	LevelCodeTxt:SetText("Hai")
	function LevelCodeTxt:Paint()
		surface.SetDrawColor( 255, 198, 0, 255 )
		surface.DrawOutlinedRect( 0, 0, LevelCodeTxt:GetWide(), LevelCodeTxt:GetTall() )
		for i = 1, 10 do
			surface.DrawOutlinedRect( i / 2, i / 2, LevelCodeTxt:GetWide() - i , LevelCodeTxt:GetTall() - i )
		end
		surface.SetDrawColor( 255, 255, 255, 255 )
		surface.DrawRect( 5, 5, LevelCodeTxt:GetWide() - 10, LevelCodeTxt:GetTall() - 10 )
		if StageListView:GetLine(StageListView:GetSelectedLine()) then
			draw.SimpleTextOutlined(tostring(StageListView:GetLine(StageListView:GetSelectedLine()):GetValue(2)), "HUDNumber5", 10, LevelCodeTxt:GetTall() * 0.15, Color( 255, 255, 255, 255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT, 2, Color(0,0,0,255))
		end
	end
	
end


